package com.chub;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.engine.BeetlTemplateEngine;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.baomidou.mybatisplus.generator.fill.Column;

import java.util.Arrays;
import java.util.List;


/**
 * @author : chub
 * @version : V1.0.0
 * @fileName : Generator1.java
 * @description : TODO
 * @createTime : 2024-08-17 18:00
 */
public class Generator1 {

    /**
     * 数据源信息
     */
    private static final String URL = "jdbc:mysql://localhost:3306/chubtest?useUnicode=true&characterEncoding=utf8&useSSL=false";
    private static final String DRIVER_NAME = "com.mysql.cj.jdbc.Driver";
    private static final String USERNAME = "root";
    private static final String PASSWORD = "root";

    /**
     * 数据源配置
     */
    private static final DataSourceConfig.Builder DATA_SOURCE_CONFIG = new DataSourceConfig
            .Builder(URL, USERNAME, PASSWORD);

    public static void main(String[] args) {


        List<String> tables = Arrays.asList("t_psn_info".split(","));


        FastAutoGenerator.create(DATA_SOURCE_CONFIG)
                // 全局配置
                .globalConfig(builder -> builder.author("chub").outputDir(System.getProperty("user.dir") + "/springbootStudy/codeGenerator/src/main/java"))
                // 包配置
                .packageConfig((scanner, builder) -> builder.parent("com.chub.study.modules")
                        .service("service")
                        .serviceImpl("service.impl")
                        .controller("controller")
                        .mapper("mapper")
                        .xml("mapper")
                        .equals("entity"))
                // 策略配置
                .strategyConfig((builder) -> builder.addInclude(tables)
                        .addTablePrefix("tb_")//设置过滤表前缀
                        .controllerBuilder().enableRestStyle().enableHyphenStyle()
                        .entityBuilder().enableLombok().addTableFills(
                                new Column("create_time", FieldFill.INSERT)
                        ).build())
                //模板引擎配置，默认 Velocity 可选模板引擎 Beetl 或 Freemarker
                // .templateEngine(new BeetlTemplateEngine())
                // .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}
